Skip to content

fix: MN port validation on mainnet is broken after 6627 #6664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 12, 2025

Conversation

UdjinM6
Copy link

@UdjinM6 UdjinM6 commented May 10, 2025

Issue being fixed or feature implemented

#6627 broke MN port validation on mainnet - develop fails with bad-protx-netinfo-port for a completely valid protx

What was done?

Implement it the way it was before https://github.com/dashpay/dash/pull/6627/files#diff-0998f8dfc4c1089e90cbaafe9607b361035b904cd103df31e3c2339a3cbf790dL1189-L1195

How Has This Been Tested?

Sync on mainnet

Breaking Changes

n/a

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@UdjinM6 UdjinM6 added this to the 23 milestone May 10, 2025
Copy link

coderabbitai bot commented May 10, 2025

Walkthrough

The validation logic for the service port in src/evo/netinfo.cpp was simplified by replacing a two-branch conditional with a single combined conditional expression that checks whether the node is on mainnet and if the service port matches the mainnet default port. The semantics remain unchanged: the service port must be the mainnet default port if and only if the node is on mainnet. In src/test/evo_netinfo_tests.cpp, the test suite was updated to use BasicTestingSetup instead of RegTestingSetup, with test vectors adjusted to use new port numbers (replacing port 8888 with 9999 and related changes). A new test case was added to verify rejection of internal addresses. No public interfaces were modified.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20afc99 and 2e8c7ef.

📒 Files selected for processing (2)
  • src/evo/netinfo.cpp (1 hunks)
  • src/test/evo_netinfo_tests.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/evo/netinfo.cpp
🧰 Additional context used
🪛 Cppcheck (2.10-2)
src/test/evo_netinfo_tests.cpp

[error] 14-14: There is an unknown macro here somewhere. Configuration is required. If BOOST_FIXTURE_TEST_SUITE is a macro then please configure it.

(unknownMacro)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
🔇 Additional comments (5)
src/test/evo_netinfo_tests.cpp (5)

14-14: Good update to the test fixture setup.

Changing from RegTestingSetup to BasicTestingSetup is appropriate for properly testing mainnet port validation behavior, which aligns with the PR objective of fixing mainnet MN port validation.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 14-14: There is an unknown macro here somewhere. Configuration is required. If BOOST_FIXTURE_TEST_SUITE is a macro then please configure it.

(unknownMacro)


18-18: Port number update looks good.

Updating the port from 8888 to 9999 is consistent with the port changes needed to fix the MN port validation on mainnet.


22-22: Test case correctly updated for mainnet port validation.

The test now properly checks that using a non-mainnet port (9998) on mainnet fails with BadPort status, which directly addresses the issue this PR is fixing.


24-24: Good addition of internal address rejection test.

Adding a test case to verify that internal addresses like 127.0.0.1 are rejected on mainnet improves security validation coverage.


26-36: Port number updates are consistent.

All instances of port 8888 have been correctly updated to 9999 throughout the test cases, maintaining consistency with the required changes for proper mainnet port validation.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/evo/netinfo.cpp (1)

40-44: Optional: Simplify nested if/else for brevity
For a more concise style, you can combine both branches into a single condition:

-if (IsNodeOnMainnet()) {
-    if (service.GetPort() != default_port_main) {
-        return NetInfoStatus::BadPort;
-    }
-} else if (service.GetPort() == default_port_main) {
-    return NetInfoStatus::BadPort;
-}
+if ((IsNodeOnMainnet() && service.GetPort() != default_port_main) ||
+    (!IsNodeOnMainnet() && service.GetPort() == default_port_main)) {
+    return NetInfoStatus::BadPort;
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f94e3e and 20afc99.

📒 Files selected for processing (1)
  • src/evo/netinfo.cpp (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check Potential Conflicts
src/evo/netinfo.cpp

[error] 1-1: Merge conflict detected in this file. Conflicting PR #6629 affects this file.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
🔇 Additional comments (2)
src/evo/netinfo.cpp (2)

1-86: Resolve merge conflicts with PR #6629
A merge conflict was detected in this file with changes from PR #6629. Please ensure that the MN port validation fix here and any other updates introduced by #6629 are correctly merged so no logic is lost or duplicated.

🧰 Tools
🪛 GitHub Actions: Check Potential Conflicts

[error] 1-1: Merge conflict detected in this file. Conflicting PR #6629 affects this file.


40-44: Correctly restored mainnet port validation logic
This change accurately reverts the port validation to its pre-#6627 state: on mainnet only the default port is accepted, and the default mainnet port is prohibited off-mainnet, preserving the intended behavior.

@UdjinM6 UdjinM6 changed the title fix: MN port validation is broken after 6627 fix: MN port validation on mainnet is broken after 6627 May 10, 2025
knst
knst previously approved these changes May 10, 2025
Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 20afc99

Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider 4b839a3 from dash#6629 for test suite changes.

@knst
Copy link
Collaborator

knst commented May 11, 2025

Consider 4b839a3 from dash#6629

This condition is a bit messy because IsNodeOnMainnet used twice in different branches and as A and !A.

if (IsNodeOnMainnet() && service.GetPort() != default_port_main) {


        // Must use mainnet port on mainnet

        return NetInfoStatus::BadPort;
    } else if (!IsNodeOnMainnet() && service.GetPort() == default_port_main) {

Consider refactoring such as: if (fbool port_is_mainnet = service.GetPort() == default_port_main; IsNodeOnMainet() == port_is_mainnet) {...}

Otherwise it's too messy

@kwvg
Copy link
Collaborator

kwvg commented May 11, 2025

@knst I don't mind retaining the condition as proposed here, was moreso interested in having the test changes from the commit incorporated to expand coverage.

Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 2e8c7ef

Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 2e8c7ef

@PastaPastaPasta PastaPastaPasta merged commit e853d0b into dashpay:develop May 12, 2025
31 of 34 checks passed
PastaPastaPasta added a commit that referenced this pull request May 28, 2025
…n-`CService` entries, use in `MnNetInfo`

3a72f2f evo: fast-fail `MnNetInfo::AddEntry()` if invalid characters found (Kittywhiskers Van Gogh)
e0a1c64 evo: prohibit overwriting entry in `MnNetInfo` (Kittywhiskers Van Gogh)
c69184b evo: utilize `NetInfoEntry::IsTriviallyValid()` in ProTx trivial checks (Kittywhiskers Van Gogh)
06cf4ee evo: return `MnNetInfo::GetEntries()` with `NetInfoEntry` (Kittywhiskers Van Gogh)
6286c9b evo: change internal type of `MnNetInfo` to `NetInfoEntry` (Kittywhiskers Van Gogh)
b0a634e evo: ensure the ADDRV2 serialization is always used in `NetInfoEntry` (Kittywhiskers Van Gogh)
6d97bda evo: introduce type-flexible `NetInfoEntry` to allow non-`CService` data (Kittywhiskers Van Gogh)
069583d evo: expand error codes for `netInfo` validation (Kittywhiskers Van Gogh)

Pull request description:

  ## Motivation

  The upcoming extended addresses specification envisions the ability to store address information _beyond_ the set of addresses that can be represented by BIP-155 (i.e. `CService`). To enable this, we need to devise a backwards-compatible way to allow storing and manipulating address information with differing serialization formats and validation rules.

  Backwards compatibility is a priority as the unique properties set (used to detect attempts at storing already-registered values) only stores a hashed representation of the value and therefore, in-place migration is not a viable option.

  With this in mind, this pull request introduces `NetInfoEntry`, which is wrapper around an `std::variant` that provides dispatching for common endpoints with `std::visit`, serialization and trivial validity enforcement between potential implementations and the ability to access the underlying type if necessary (for code that relies on backwards-compatibility, like hashing). It doesn't implement any network rules itself but requires that it must hold a valid instance of any underlying type that it supports.

  While `MnNetInfo` (the current implementation) has and always will store a `CService`, to ensure a conformity between it and `ExtNetInfo` (the upcoming extended implementation), its public functions will return a `NetInfoEntry` when applicable so that both can be abstracted by a common interface to aid with the transition.

  ## Additional Information

  * Depends on #6627

  * Depends on #6664

  * Dependency for #6665

  * ~~2e9bde0519b242d1d7aaf49344a357b90121689e in [dash#6627](#6627) incorrectly migrated validation conditions such that attempting to set a valid `addr:port` combination on mainnet would result in a `BadPort` error because the non-mainnet rules were applied _regardless_ of network.~~

    ~~This evaded testing as our unit and functional tests do not run on mainnet. To prevent this from occurring again, the whole `evo_netinfo_tests` suite now uses `BasicTestingSetup` (which advertises itself as mainnet), which comes with the added benefit of greater coverage as mainnet rules are _stricter_.~~

    ~~The port validation check for non-mainnet networks are tested _indirectly_ through tests like `evo_simplifiedmns_merkleroots`'s usage of `NetInfoInterface::*` methods ([source](https://github.com/dashpay/dash/blob/0f94e3e3e793925caa24a73ad54d843770b1a8c5/src/test/evo_simplifiedmns_tests.cpp#L25)).~~ Superseded by [dash#6664](#6664).

  * Per replies to review comments ([comment](#6627 (comment)), [comment](#6627 (comment))) from [dash#6627](#6627), reported error codes from `netInfo` interactions have been expanded to be more specific.

  * `CService` by default is serialized using ADDRV1 and utilizing ADDRV2 serialization is either explicitly opted into ([source](https://github.com/dashpay/dash/blob/0f94e3e3e793925caa24a73ad54d843770b1a8c5/src/addrman.cpp#L173-L175)) or determined on-the-fly ([source](https://github.com/dashpay/dash/blob/0f94e3e3e793925caa24a73ad54d843770b1a8c5/src/net_processing.cpp#L3960-L3965)). As we envision the ability to store Tor and I2P addresses, using ADDRV2 is mandatory.

    Though this affects (de)serialization of `NetInfoEntry`, it does not affect `MnNetInfo` as `NetInfoEntry` is only used for the sake of a consistent interface _but_ internally still (de)serializes to an ADDRV1 `CService`.

  * The introduction of fast-failing based on permitted characters is meant to mirror the upcoming extended addresses implementation where permitted characters are used as a quick way to classify the intended underlying type before running more expensive checks.

    As a side effect, this may cause inconsistency where attempting to use `MnNetInfo::AddEntry()` with, for example, an IPv6 address will result in `BadInput` as the delimiter used in IPv6 addresses are not part of the permitted characters filter _but_ validating a `MnNetInfo` with an IPv6 address _already stored_ will return a `BadType`.

  ## Breaking Changes

  None expected.

  ## Checklist

  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas
  - [x] I have added or updated relevant unit/integration/functional/e2e tests
  - [x] I have made corresponding changes to the documentation **(note: N/A)**
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  PastaPastaPasta:
    utACK 3a72f2f
  UdjinM6:
    utACK 3a72f2f

Tree-SHA512: abd84db309b6011480431b12cccd649878bab06aa44ca2c81563e9598d4424fd61888b12e2e439b9c2180bc5e0edee3431b1008ae7af4b676b164af1455fda3c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants